package com.member.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.member.domain.MemberCommand;

public class JoinValidator implements Validator {

	@Override
	public boolean supports(Class<?> clazz) {
		
		return MemberCommand.class.isAssignableFrom(clazz);
	}

	@Override
	public void validate(Object target, Errors errors) {
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "name", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "id", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "password", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "passwordconfirm", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "spassword", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "apassword", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email1", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "email2", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone1", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone2", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "phone3", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "birth1", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "birth2", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "birth3", "required");
		ValidationUtils.rejectIfEmptyOrWhitespace(errors, "sex", "required");
	}
}